package cn.com.joco.dk.core.web;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import cn.com.joco.dk.webby.model.User;
import cn.com.joco.dk.webby.service.user.UserService;



public class AdminInterceptor extends HandlerInterceptorAdapter {
	
	
	
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		setUser(request, response);
		return super.preHandle(request, response, handler);
	}

	public void setUser(HttpServletRequest request,
			HttpServletResponse response){
		Subject subject=SecurityUtils.getSubject();
		Object principal = subject.getPrincipal();
		String loginid=principal==null?null:String.valueOf(principal);
		User user=null;
		user=userService.findByloginId(loginid);
		request.setAttribute("user", user);
	}

	@Resource
	private UserService userService;
}
